home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / PCI Driver Development Kit / • Tools / Development / NCR.flash / NCR-FLASH.of < prev    next >
Encoding:
Text File  |  1996-08-20  |  2.7 KB  |  113 lines  |  [TEXT/MPS ]

  1. \ *****************************************************************************
  2. \    NCR-FLASH.of, simple program to flash an image into the NCR-8250 card's ROM.
  3. \
  4. \    This code is meant to be down-loaded into Open Firmware via the DL command.
  5. \    It makes assumptions about the location of the NCR card:  it expects
  6. \    the card in the middle slot of the first Bandit (i.e., device-E).  If you
  7. \    place the card in another slot, the values for NCRbase and ROM defined
  8. \    below have to be adjusted accordingly.  Since the code needs to do config
  9. \    cycles to setup the ROM base address, etc. it will install itself into the
  10. \    Bandit's device-node so that it can get access to its CONFIG words.
  11. \
  12. \    To erase the ROM, use NV-ERASE.
  13. \    To program the ROM, use NV-FLASH.  NV-FLASH takes 2 arguments on the stack.
  14. \    Its stack diagram is:
  15. \    NV-FLASH    ( adr len -- )
  16. \    where ADR is an address in memory containing the source image and LEN is
  17. \    that image's length.
  18. \
  19. \    You can use the DUMP-CREATE form of Tokenize output to make a CREATE image
  20. \    that can be down-loaded.
  21. \
  22. \    The code uses the 1 µsec timer of the SWIM chip to do its timing, so it
  23. \    should be independent of processor speed.
  24. \ *****************************************************************************
  25.  
  26. dev /bandit
  27. hex
  28. 00007000    constant NCRbase    \ /bandit/@e
  29. 8FFF8000    constant ROM        \ /bandit memory space
  30.  
  31. F3015010 constant usecTIMER
  32. : usecs    ( #usecs -- )
  33.     usecTIMER rb!            \ stash to SWIM's usec counter
  34.     begin
  35.         usecTIMER rb@ while
  36.         repeat
  37.     ;
  38.  
  39. ROM dup 8000 28 do-map
  40. ROM 1+ NCRbase 30 + config-l!
  41. 2 NCRbase 4 + config-l!
  42.  
  43. : NV-enable
  44.     10 NCRbase 87 + config-b!
  45.     ;
  46. : NV-disable
  47.     00 NCRbase 87 + config-b!
  48.     ;
  49.  
  50. : NV-clear
  51.     8000 0 do
  52.         40 rom rb!
  53.         0 rom i + rb!
  54.         d# 10 usecs            \ about 10 µsec
  55.         C0 rom i + rb!
  56.         d# 6 usecs            \ about 6 µsec
  57.         rom i + rb@ drop
  58.         loop
  59.     ;
  60. 0 value ADDR
  61. 0 value LEN
  62. : NV-erase    ( -- )
  63.     NV-enable
  64.     NV-clear
  65.     0 to ADDR
  66.     begin
  67.         20 rom rb!            \ Set-Up Erase
  68.         20 rom rb!            \ Erase
  69.         d# 100 0 do            \ 10 msec loop
  70.             d# 100 usecs
  71.             loop
  72.         begin
  73.             A0 rom ADDR + rb!
  74.             rom rb@ FF = while
  75.             ADDR 1+ to ADDR
  76.             ADDR 8000 >= if
  77.                 exit
  78.               then
  79.             repeat
  80.         key? if
  81.             NV-disable
  82.             ." NV-erase aborted"
  83.             abort
  84.           then
  85.         again
  86.     NV-disable
  87.     ;
  88. : NV-flash    ( addr len )
  89.     to LEN    to ADDR
  90.     NV-enable
  91.     LEN 0 do
  92.         true                            \ assume bad result
  93.         d# 25 0 do
  94.             40 ROM rb!                    \ Set-Up Program
  95.             ADDR j + c@ ROM j + rb!        \ Program Data
  96.             d# 10 usecs
  97.             C0 ROM rb!                    \ Program Verify
  98.             d# 6 usecs
  99.             ADDR j + c@ ROM rb@ = if    \ check it
  100.                 drop false leave        \ exit loop with OK
  101.               then
  102.              loop
  103.         ( not-OK flag ) if                    \ we tried 25 times without success
  104.             ." programming failure; "
  105.             ." ADDR=" ADDR .h
  106.             ." , DATA =" ADDR i + c@ .h
  107.             NV-disable
  108.             abort
  109.           then
  110.         loop
  111.     NV-disable
  112.     ;
  113.